package com.jiukuaidao.library.widget.recyclerview.ref.impl.header1;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.jiukuaidao.library.util.ScreenUtils;
import com.jiukuaidao.library.widget.recyclerview.ref.IRefreshFooter;
import com.jiukuaidao.library.widget.recyclerview.ref.IRefreshHeader;

public class LoadingMoreFooter extends LinearLayout {

    private SimpleViewSwitcher progressCon;
    public final static int STATE_LOADING = 0;
    public final static int STATE_COMPLETE = 1;
    public final static int STATE_NOMORE = 2;
    private TextView mText;


    public LoadingMoreFooter(Context context) {
        super(context);
        initView();
    }

    /**
     * @param context
     * @param attrs
     */
    public LoadingMoreFooter(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();

    }

    public void initView() {
        setGravity(Gravity.CENTER);
        setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        progressCon = new SimpleViewSwitcher(getContext());
        progressCon.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

        AVLoadingIndicatorView progressView = new AVLoadingIndicatorView(this.getContext());
        progressView.setIndicatorColor(0xffB5B5B5);
        progressView.setIndicatorId(ProgressStyle.BallSpinFadeLoader);
        progressCon.setView(progressView);

        addView(progressCon);
        mText = new TextView(getContext());
        LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.height = ScreenUtils.dip2px(getContext(),78);
        layoutParams.setMargins(ScreenUtils.dip2px(getContext(),10), 0, 0, 0);
        mText.setGravity(Gravity.CENTER);
        mText.setLayoutParams(layoutParams);
        addView(mText);
    }

    public void setProgressStyle(int style) {
        if (style == ProgressStyle.SysProgress) {
            progressCon.setView(new ProgressBar(getContext(), null, android.R.attr.progressBarStyle));
        } else {
            AVLoadingIndicatorView progressView = new AVLoadingIndicatorView(this.getContext());
            progressView.setIndicatorColor(0xffB5B5B5);
            progressView.setIndicatorId(style);
            progressCon.setView(progressView);
        }
    }

    public void setState(int state) {
        switch (state) {
            case IRefreshFooter.STATE_LOADING:
                mText.setText("正在加载");
                break;
            case IRefreshFooter.STATE_COMPLETE:
                mText.setText("加载完成");
                break;
            case IRefreshFooter.STATE_NOMORE:
                mText.setText("无更多数据");
                break;
            case IRefreshFooter.STATE_NORMAL:
                mText.setText("上拉加载");
                break;
            case IRefreshFooter.STATE_RELEASE_LOAD:
                mText.setText("释放加载");
                break;
            case IRefreshHeader.STATE_NORMAL:
                mText.setText("下拉刷新");
                break;
            case IRefreshHeader.STATE_RELEASE_TO_REFRESH:
                mText.setText("释放刷新");
                break;
            case IRefreshHeader.STATE_REFRESHING:
                mText.setText("正在刷新");
                break;
            case IRefreshHeader.STATE_DONE:
                mText.setText("刷新完成");
                break;
        }
    }
}
